var mongoose=require('mongoose');
var User=mongoose.model('User',{
    name:String,
    number:Number,
    winner:Boolean
});
var db=mongoose.connect('mongodb://localhost/MongoDB_QuanWei_2');


User.update({name:'A'},{number:1101,winner:true},{upsert:true},(e,r)=>{
    if(e)throw e;
    console.log('Update:\n',r);

    User.update({name:'B'},{number:1201,winner:false},{upsert:true},(e,r)=>{
        if(e)throw e;
        console.log('Update:\n',r);


        User.update({name:'C'},{number:1301,winner:true},{upsert:true},(e,r)=>{
            if(e)throw e;
            console.log('Update:\n',r);

            User.update({name:'D'},{number:1401,winner:false},{upsert:true},(e,r)=>{
                if(e)throw e;
                console.log('Update:\n',r);

                User.find({
                    number:{$in:[1101,1301]}
                },(e,r)=>{
                    if(e)throw e;
                    console.log('\nFind:\n',JSON.stringify(r,null,2));

                    //相当于
                    process.exit(1);
                });


            });

        });

    });

});


/*
* {field:{$in:[val1,val2,...]}
*
* $in:一个值匹配多个值中的一个
* 相当于对单个字段做OR查询
* */
